import { useEffect, useState } from "react";
// 制作自定义HOOKS  
// 这时候就需要把React.FC去除
export const UseMoverFun = (delay:number=500) => {
    const [postion,setPotion] = useState({ x: 0, y: 0 });
    useEffect(()=>{
        // 做节流处理
        let timeID:null | NodeJS.Timeout = null;
        const CallBack = (e:MouseEvent)=>{
            timeID =  setTimeout(()=>{
                setPotion({x:e.clientX,y:e.clientY});
                timeID = null;
            },delay)
        }
        window.addEventListener("mousemove",CallBack);
        return ()=>{
            window.removeEventListener("mousemove",CallBack);
        }
    },[])
    // return (
    //     <><h1>鼠标位置{JSON.stringify(postion)}</h1></>
    // )
    return postion
}


